package com.baizhi.service.impl;

import com.baizhi.dao.ArticleDao;
import com.baizhi.entity.Article;
import com.baizhi.service.ArticleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by 野马 on 2019/6/21.
 */

@Service
public class ArticleServiceImpl implements ArticleService {

    @Autowired
    private ArticleDao articleDao;

    @Override
    public Map selectArticle(String articleName, int page, int rows) {
        //从第几条开始
        int start = (page-1)*rows;
        int pageSize = rows;

        if(articleName != null && !"".equals(articleName)){
            articleName = "%"+articleName+"%";
        }else {
            articleName = null;
        }

        int countArticle = articleDao.selectCountArticle(articleName);
        List<Article> articleList = articleDao.selectArticle(articleName, start, pageSize);
        Map map = new HashMap();
        map.put("total",countArticle);
        map.put("rows",articleList);
        return map;
    }

    @Override
    public List<Article> selectArticleAll(String articleType) {
        return articleDao.selectArticleAll(articleType);

    }
}
